home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Shared / MM / Scripts / CMN / file.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  2.2 KB  |  68 lines

  1. //
  2. // Copyright 1999 Macromedia, Inc. All rights reserved.
  3. //
  4. //file.js
  5. //
  6. //Library of functions pertaining to file functions.
  7. //
  8. //--------------------------------------------------------------
  9. //
  10. //browseFile(fieldToStoreURL){
  11. //function getFullPath(filePathURL){
  12.  
  13.  
  14. //Invokes dialog to allow user to select filename. Puts value in text input.
  15.  
  16. function browseFile(fieldToStoreURL){
  17.   var fileName = "";
  18.   fileName = browseForFileURL();  //returns a local filename
  19.   if (fileName) fieldToStoreURL.value = fileName;
  20. }
  21.  
  22.  
  23. //function: getFullPath
  24. //description: converts relative paths into full paths that start with
  25. //file:///
  26. //Why this is important: A user is prompted for a location to save
  27. //a file. Dreamweaver generates a path that is relative to the currently
  28. //opened document. If a developer tries to use this URL in DWfile, it will
  29. //not work because dreamweaver assumes the path to be relative to the 
  30. //extension file. However, full paths will work
  31. //Note that this function sometimes returns a full path that is indirect:
  32. //For instance: file:///C|/MyWebSite/Hobbies/Cooking/.../Hobbies/Images/cake.gif
  33. //However, the user never sees this file path.
  34. //
  35. //Arguments:
  36. //filePathURL - doc-relative,site-relative, or absolute file path
  37.  
  38. function getFullPath(filePathURL){
  39.    var retVal = (filePathURL)?filePathURL:'';
  40.    var docURL;
  41.    var dotDotSlash;
  42.    var inMiddle;
  43.   
  44.   if (retVal != ''){ 
  45.      //if the document path is relative, for example,My Docs/My Schedule.htm
  46.      //create an absolute path. 
  47.      if (  filePathURL.indexOf("file://")!=0  ){ 
  48.        
  49.          //if doc relative...
  50.        if ( filePathURL.charAt(0)!="/"  ){
  51.            docURL = dreamweaver.getDocumentDOM('document').URL;
  52.          dotDotSlash = filePathURL.indexOf('../');
  53.          while (dotDotSlash == 0){
  54.            docURL = docURL.substring(0,docURL.lastIndexOf("/"));
  55.            filePathURL = filePathURL.substring(3);
  56.            dotDotSlash = filePathURL.indexOf('../');
  57.          } 
  58.          retVal = docURL.substring(0,docURL.lastIndexOf("/")+1) + filePathURL;  
  59.          //else path is site relative...
  60.          } else {
  61.            retVal = dreamweaver.getSiteRoot() + filePathURL.substring(1);
  62.          } 
  63.      }
  64.    }
  65.      return retVal;
  66. }
  67.  
  68.